package com.ge.boot08rpc.service;

import com.ge.boot08rpc.Interface.HttpInterface;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
import reactor.core.publisher.Mono;

/**
 * 测试 Http Interface
 */

@Service
public class HttpInterfaceService {


    public Mono<String> doQuery(String param) {

        // 创建客户端
        WebClient client = WebClient.builder()
                // 定义远程调用的地址、端口或域名
                .baseUrl("https://ip:port")
                .build();

        // 创建代理工厂
        HttpServiceProxyFactory proxyFactory = HttpServiceProxyFactory
                .builderFor(WebClientAdapter.create(client))
                .build();

        // 传入接口，获取动态代理对象
        HttpInterface factoryClient = proxyFactory.createClient(HttpInterface.class);

        // 调用接口进行查询
        return factoryClient.doQuery(param);
    }

}
